﻿using Minecraft.Config;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Minecraft.ServerHall
{
	public static class PhysicalStrengthValue
	{
		/// <summary>
		/// 设置玩家当前的体力值
		/// </summary>
		/// <param name="session"></param>
		/// <returns></returns>
		public static void SetCurPhysicalStrengthValue(this MinecraftSession session)
		{
			var timeNow = DateTimeOffset.Now;

			//if (JsonConfig.Value.IsDebug)
			//{
			//	session.minecraftSessionInfo.player.PhysicalStrengthValue = MinecraftConfig.PhysicalStrengthUpperLimit - 4;
			//	session.minecraftSessionInfo.player.PhysicalStrengthLastGrowTime = timeNow.AddSeconds(-(MinecraftConfig.growthRateOfPhysicalStrengthValue.key * 3 + 6));
			//}

			var seconds = Convert.ToInt32((timeNow - session.minecraftSessionInfo.player.PhysicalStrengthLastGrowTime).TotalSeconds);
			if (seconds < MinecraftConfig.growthRateOfPhysicalStrengthValue.Key)
			{
				//最近一次增长时刻距离当前时间小于指定值，不处理
			}
			else
			{
				var canAddVal = seconds / MinecraftConfig.growthRateOfPhysicalStrengthValue.Key;
				var modSecond = seconds % MinecraftConfig.growthRateOfPhysicalStrengthValue.Key;
				session.minecraftSessionInfo.player.PhysicalStrengthValue += canAddVal * MinecraftConfig.growthRateOfPhysicalStrengthValue.Value;
				if (session.minecraftSessionInfo.player.PhysicalStrengthValue < MinecraftConfig.PhysicalStrengthUpperLimit)
				{
					session.minecraftSessionInfo.player.PhysicalStrengthLastGrowTime = session.minecraftSessionInfo.player.PhysicalStrengthLastGrowTime.AddSeconds(MinecraftConfig.growthRateOfPhysicalStrengthValue.Key * canAddVal);
				}
				else
				{
					session.minecraftSessionInfo.player.PhysicalStrengthValue = MinecraftConfig.PhysicalStrengthUpperLimit;
					session.minecraftSessionInfo.player.PhysicalStrengthLastGrowTime = timeNow;
				}
			}
		}
	}
}
